home *** CD-ROM | disk | FTP | other *** search
- //
- // TESTDEMO Demonstration of Test Matrix Toolbox.
- // N. J. Higham.
-
- // This file is a translation of tmtdemo.m from version 2.0 of
- // "The Test Matrix Toolbox for Matlab", described in Numerical
- // Analysis Report No. 237, December 1993, by N. J. Higham.
-
- "The Test Matrix Toolbox contains test matrices, visualization routines,"
- "and other miscellaneous routines.\n"
-
- "The version of the toolbox is RLaB Port of v2.0\n"
-
- "For this demonstration you will need to view both the command window"
- "and one figure window."
- "This demonstration emphasises graphics and shows only"
- "some of the features of the toolbox.\n"
-
- "First, lets load all of the Rfiles in the testmatrix directory"
- "Note: you must be executing this file from the testmatrix directory.\n"
-
- rfile loadtm
-
- "The FV command plots the boundary of the field of values of a matrix"
- "(the set of all Rayleigh quotients) and plots the eigenvalues as"
- "crosses (`x'). Here are some examples:\n"
-
- "The Grcar matrix is a Toeplitz matrix of the following form:"
-
- grcar(5)
-
- "Here is the field of values of the 10-by-10 Grcar matrix:"
-
- ptitle ("fv (grcar (10))");
- fv (grcar (10));
- pause ("");
-
- "Next, we form a random orthogonal matrix and look at its field of values."
- "The boundary is the convex hull of the eigenvalues since A is normal.\n"
-
- ptitle("randsvd (10, 1)");
- A = randsvd (10, 1);
- fv (A);
- pause ();
-
- "The RANDSVD commands generates random matrices with pre-assigned"
- "condition number, and various singular value distributions:\n"
-
- A = randsvd(6, 1e6, 3); // Exponential distribution.
-
- svd(A).sigma.'
- 1/rcond (A)
- pause ();
-
- "The PS command plots an approximation to a pseudospectrum of A,"
- "which is the set of complex numbers that are eigenvalues of some"
- "perturbed matrix A + E, with the norm of E at most epsilon"
- "(default: epsilon = 1E-3)."
- "The eigenvalues of A are plotted as crosses (`x')."
- "Here are some interesting PS plots.\n"
-
- "First, we use the KAHAN matrix, a triangular matrix made up of sines and"
- "cosines. Here is an approximate pseudospectrum of the 10-by-10 matrix:\n"
-
- ptitle ("ps(kahan(10))");
- ps (kahan (10), 25);
- pause ();
-
- "The TRIW matrix is upper triangular, made up of 1s and -1s:\n"
-
- triw (4)
-
- "The following matrix has a pseudospectrum in the form of a limacon.\n"
-
- ptitle ();
- n = 25;
- A = triw(n,1,2) - eye(n,n);
- sub (A, 6) // Leading principal 6-by-6 submatrix of A.
- ps (A);
- pause ();
-
- "Here is the 8-by-8 Frank matrix.\n"
- A = frank(8)
-
- "We can get a visual representation of the matrix using the SEE"
- "command, which produces subplots with the following layout:"
- " |---------------------------------|"
- " | MESH(A) MESH(INV(A)) |"
- " | SEMILOGY(SVD(A)) FV(A) |"
- " |---------------------------------|"
- "where FV is the field of values.\n"
-
- pclose ();
- pstart (2,2);
- see(A);
- pause ();
-
- "The Frank matrix is well-known for having ill-conditioned eigenvalues."
- "Here are the eigenvalues (in column 1) together with the corresponding"
- "eigenvalue condition numbers (in column 2):\n"
-
- es = eigsens (A);
- [es.val.', es.sens, 1./es.val.']
-
- "In the last column are shown the reciprocals of the eigenvalues."
- "Notice that if LAMBDA is an eigenvalue, so is 1/LAMBDA!\n"
-
- pause ();
-
- "MAGIC function produces magic squares:\n"
-
- A = magic(5)
-
- "Using the toolbox routine PNORM we can estimate the matrix p-norm"
- "for any value of p.\n"
-
- [pnorm(A,1), pnorm(A,1.5), pnorm(A,2), pnorm(A,pi), pnorm(A,inf())]
-
- "As this example suggests, the p-norm of a magic square is"
- "constant for all p!\n"
-
- pause ();
-
- "GERSH plots Gershgorin disks. Here are some interesting examples.\n"
-
- ptitle("gersh(lesp(12))");
- gersh(lesp(12));
- pause ();
-
-
- ptitle("gersh(hanowa(10))");
- gersh(hanowa(10));
- pause ();
-
- ptitle("gersh(ipjfact(6,1))");
- gersh(ipjfact(6,1).A);
- pause ();
-
- ptitle("gersh(smoke(16,1))");
- gersh(smoke(16,1));
- pause ();
- pclose();
-
-
- "A Hadamard matrix has elements 1 or -1 and mutually orthogonal rows:"
-
- hadamard(4)
-
- "A CONTOUR plot of this matrix is interesting:"
-
- pstart (1,1);
- plcont(<< x=1:16; y=1:16; z=hadamard(16) >>);
- pause ();
-
- "GFPP generates matrices for which Gaussian elimination with partial"
- "pivoting produces a large growth factor."
-
- gfpp(6)
- pause ();
-
- "Let's find the growth factor for partial pivoting and complete pivoting"
- "for a bigger matrix:"
-
- A = gfpp(20);
-
- "Partial pivoting."
- LU = lu(A);
- max(max(abs(LU.u))) / max(max(abs(A)))
-
- "Complete pivoting using toolbox routine GECP."
- LUPQrho = gecp(A);
- LUPQrho.rho
-
- "As expected, complete pivoting does not produce large growth here."
-
- pause ();
- clearall ();
- format ();
-